package fr.esiag.isidis.epp.launcher;


import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import fr.esiag.isidis.epp.generatedClasses.PointConso;
import fr.esiag.isidis.epp.generatedClasses.Query;
import fr.esiag.isidis.epp.generatedClasses.QueryExportCdc;
import fr.esiag.isidis.epp.search.PointCdcService;
import fr.esiag.isidis.epp.service.JaxbConverter;

public class EPPLauncher 
{
	private static Logger logger = Logger.getLogger(EPPLauncher.class);

	public static void main( String[] args )
	{
		ApplicationContext context = new FileSystemXmlApplicationContext("classpath:/epp-context.xml");

		JaxbConverter converter = context.getBean(JaxbConverter.class);

		/*PointCdc p1 = new PointCdc();
		p1.setDateConso(20140911);
		p1.setHeureConso(10);
		p1.setPuissanceSoutire(160);
		p1.setTemperatureObservee(14);
		p1.setPoinds(8);


		PointCdc p2 = new PointCdc();
		p2.setDateConso(20140911);
		p2.setHeureConso(20);
		p2.setPuissanceSoutire(170);
		p2.setTemperatureObservee(14);
		p2.setPoinds(8);

		CourbeDeCharge c = new CourbeDeCharge();
		c.getPointCdc().add(p1);
		c.getPointCdc().add(p2);

		PointConso p = new PointConso();
		p.setIDSite("IDSITE1");
		p.setCourbeDeCharge(c);


		converter.marshallerPointConso("C:/Users/christian/Workspace/Esiag/batchs-epp2/src/main/resources/result.xml", p); */

		// unmashal xml file to java object
		QueryExportCdc pp = converter.unmarshalerPointConso("src/main/resources/query.xml");

		List<Query> list=pp.getQuery();

		PointCdcService pt = context.getBean(PointCdcService.class);
		/*Query q = list.get(0);
		System.out.println(q.toString());
		List<PointCdc> liste = pt.makeIndividuel(q);
		System.out.println("reponse fini" + liste);	
			for (PointCdc p : liste){
				System.out.println("Date : " + p.getDateConso());
				System.out.println("Heure : " + p.getHeureConso());
				System.out.println("TEMP "+ p.getTemperatureObservee());
				System.out.println("Puissance "+p.getPuissanceSoutire());
				System.out.println("POIDS "+p.getPoinds());
			} */
		PointConso pc =  pt.traiteQuery(pp);
		converter.marshallerPointConso("src/main/resources/result1.xml", pc);
		logger.info("XML RETOUR GENERER");
		}
}
